/**
 * Copyright &copy; 2012-2016 <a href="https://www.kaaction.com">KAA</a> All rights reserved All rights reserved.
 */
package com.kaaction.modules.ka.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.kaaction.common.persistence.Page;
import com.kaaction.common.web.BaseController;
import com.kaaction.common.utils.StringUtils;
import com.kaaction.modules.ka.entity.KaSupplier;
import com.kaaction.modules.ka.service.KaSupplierService;

/**
 * 供应商Controller
 * @author huanghaiming
 * @version 2017-06-14
 */
@Controller
@RequestMapping(value = "${adminPath}/ka/kaSupplierChoose")
public class KaSupplierChooseController extends BaseController {

	@Autowired
	private KaSupplierService kaSupplierService;
	
	@ModelAttribute
	public KaSupplier get(@RequestParam(required=false) String id) {
		KaSupplier entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = kaSupplierService.get(id);
		}
		if (entity == null){
			entity = new KaSupplier();
		}
		return entity;
	}
	
	@RequiresPermissions("ka:kaSupplierChoose:view")
	@RequestMapping(value = {"list", ""})
	public String list(KaSupplier kaSupplier, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<KaSupplier> page = kaSupplierService.findPage(new Page<KaSupplier>(request, response), kaSupplier); 
		model.addAttribute("page", page);
		return "modules/ka/kaSupplierChooseList";
	}

}